package com.pvdnc.tapkit.chat.chat.server;

import com.pvdnc.nsocket.server.ClientManager;
import com.pvdnc.nsocket.server.ClientProxy;
import com.pvdnc.nsocket.server.handler.SimpleServerHandler;
import com.pvdnc.tapkit.chat.chat.ChatServer;
import com.pvdnc.tapkit.chat.chat.client.KeyManager;
import com.pvdnc.tapkit.chat.chat.packet.ClientHello;

import io.netty.channel.ChannelHandlerContext;

public class OnClientHello extends SimpleServerHandler<ChatServer, ClientHello> {
    public OnClientHello(ChatServer server) {
        super(server, ClientHello.COMMAND);
    }

    @Override
    public void onReceived(ChannelHandlerContext ctx, ClientHello msg) {
        ClientProxy proxy=new ClientProxyImpl(ctx.channel());
        ClientManager.getInstance().addClient(msg.mName,proxy);

        getServer().mRSAKeyManager.putKey(msg.mName,msg.mPublicKey);
    }
}
